<?php


abstract class BaseRingtoneDownload extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $ringtone_id;


	
	protected $user_id;


	
	protected $to_phone;


	
	protected $price;


	
	protected $amount = 1;


	
	protected $download_datetime;


	
	protected $type;


	
	protected $message;


	
	protected $source_type;


	
	protected $from_phone;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getRingtoneId()
	{

		return $this->ringtone_id;
	}

	
	public function getUserId()
	{

		return $this->user_id;
	}

	
	public function getToPhone()
	{

		return $this->to_phone;
	}

	
	public function getPrice()
	{

		return $this->price;
	}

	
	public function getAmount()
	{

		return $this->amount;
	}

	
	public function getDownloadDatetime($format = 'Y-m-d H:i:s')
	{

		if ($this->download_datetime === null || $this->download_datetime === '') {
			return null;
		} elseif (!is_int($this->download_datetime)) {
						$ts = strtotime($this->download_datetime);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [download_datetime] as date/time value: " . var_export($this->download_datetime, true));
			}
		} else {
			$ts = $this->download_datetime;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getType()
	{

		return $this->type;
	}

	
	public function getMessage()
	{

		return $this->message;
	}

	
	public function getSourceType()
	{

		return $this->source_type;
	}

	
	public function getFromPhone()
	{

		return $this->from_phone;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = RingtoneDownloadPeer::ID;
		}

	} 
	
	public function setRingtoneId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->ringtone_id !== $v) {
			$this->ringtone_id = $v;
			$this->modifiedColumns[] = RingtoneDownloadPeer::RINGTONE_ID;
		}

	} 
	
	public function setUserId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v) {
			$this->user_id = $v;
			$this->modifiedColumns[] = RingtoneDownloadPeer::USER_ID;
		}

	} 
	
	public function setToPhone($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->to_phone !== $v) {
			$this->to_phone = $v;
			$this->modifiedColumns[] = RingtoneDownloadPeer::TO_PHONE;
		}

	} 
	
	public function setPrice($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->price !== $v) {
			$this->price = $v;
			$this->modifiedColumns[] = RingtoneDownloadPeer::PRICE;
		}

	} 
	
	public function setAmount($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->amount !== $v || $v === 1) {
			$this->amount = $v;
			$this->modifiedColumns[] = RingtoneDownloadPeer::AMOUNT;
		}

	} 
	
	public function setDownloadDatetime($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [download_datetime] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->download_datetime !== $ts) {
			$this->download_datetime = $ts;
			$this->modifiedColumns[] = RingtoneDownloadPeer::DOWNLOAD_DATETIME;
		}

	} 
	
	public function setType($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->type !== $v) {
			$this->type = $v;
			$this->modifiedColumns[] = RingtoneDownloadPeer::TYPE;
		}

	} 
	
	public function setMessage($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->message !== $v) {
			$this->message = $v;
			$this->modifiedColumns[] = RingtoneDownloadPeer::MESSAGE;
		}

	} 
	
	public function setSourceType($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->source_type !== $v) {
			$this->source_type = $v;
			$this->modifiedColumns[] = RingtoneDownloadPeer::SOURCE_TYPE;
		}

	} 
	
	public function setFromPhone($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->from_phone !== $v) {
			$this->from_phone = $v;
			$this->modifiedColumns[] = RingtoneDownloadPeer::FROM_PHONE;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->ringtone_id = $rs->getInt($startcol + 1);

			$this->user_id = $rs->getInt($startcol + 2);

			$this->to_phone = $rs->getString($startcol + 3);

			$this->price = $rs->getInt($startcol + 4);

			$this->amount = $rs->getInt($startcol + 5);

			$this->download_datetime = $rs->getTimestamp($startcol + 6, null);

			$this->type = $rs->getInt($startcol + 7);

			$this->message = $rs->getString($startcol + 8);

			$this->source_type = $rs->getString($startcol + 9);

			$this->from_phone = $rs->getString($startcol + 10);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 11; 
		} catch (Exception $e) {
			throw new PropelException("Error populating RingtoneDownload object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(RingtoneDownloadPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			RingtoneDownloadPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(RingtoneDownloadPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = RingtoneDownloadPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += RingtoneDownloadPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = RingtoneDownloadPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = RingtoneDownloadPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getRingtoneId();
				break;
			case 2:
				return $this->getUserId();
				break;
			case 3:
				return $this->getToPhone();
				break;
			case 4:
				return $this->getPrice();
				break;
			case 5:
				return $this->getAmount();
				break;
			case 6:
				return $this->getDownloadDatetime();
				break;
			case 7:
				return $this->getType();
				break;
			case 8:
				return $this->getMessage();
				break;
			case 9:
				return $this->getSourceType();
				break;
			case 10:
				return $this->getFromPhone();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = RingtoneDownloadPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getRingtoneId(),
			$keys[2] => $this->getUserId(),
			$keys[3] => $this->getToPhone(),
			$keys[4] => $this->getPrice(),
			$keys[5] => $this->getAmount(),
			$keys[6] => $this->getDownloadDatetime(),
			$keys[7] => $this->getType(),
			$keys[8] => $this->getMessage(),
			$keys[9] => $this->getSourceType(),
			$keys[10] => $this->getFromPhone(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = RingtoneDownloadPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setRingtoneId($value);
				break;
			case 2:
				$this->setUserId($value);
				break;
			case 3:
				$this->setToPhone($value);
				break;
			case 4:
				$this->setPrice($value);
				break;
			case 5:
				$this->setAmount($value);
				break;
			case 6:
				$this->setDownloadDatetime($value);
				break;
			case 7:
				$this->setType($value);
				break;
			case 8:
				$this->setMessage($value);
				break;
			case 9:
				$this->setSourceType($value);
				break;
			case 10:
				$this->setFromPhone($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = RingtoneDownloadPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setRingtoneId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setUserId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setToPhone($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setPrice($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setAmount($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setDownloadDatetime($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setType($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setMessage($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setSourceType($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setFromPhone($arr[$keys[10]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(RingtoneDownloadPeer::DATABASE_NAME);

		if ($this->isColumnModified(RingtoneDownloadPeer::ID)) $criteria->add(RingtoneDownloadPeer::ID, $this->id);
		if ($this->isColumnModified(RingtoneDownloadPeer::RINGTONE_ID)) $criteria->add(RingtoneDownloadPeer::RINGTONE_ID, $this->ringtone_id);
		if ($this->isColumnModified(RingtoneDownloadPeer::USER_ID)) $criteria->add(RingtoneDownloadPeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(RingtoneDownloadPeer::TO_PHONE)) $criteria->add(RingtoneDownloadPeer::TO_PHONE, $this->to_phone);
		if ($this->isColumnModified(RingtoneDownloadPeer::PRICE)) $criteria->add(RingtoneDownloadPeer::PRICE, $this->price);
		if ($this->isColumnModified(RingtoneDownloadPeer::AMOUNT)) $criteria->add(RingtoneDownloadPeer::AMOUNT, $this->amount);
		if ($this->isColumnModified(RingtoneDownloadPeer::DOWNLOAD_DATETIME)) $criteria->add(RingtoneDownloadPeer::DOWNLOAD_DATETIME, $this->download_datetime);
		if ($this->isColumnModified(RingtoneDownloadPeer::TYPE)) $criteria->add(RingtoneDownloadPeer::TYPE, $this->type);
		if ($this->isColumnModified(RingtoneDownloadPeer::MESSAGE)) $criteria->add(RingtoneDownloadPeer::MESSAGE, $this->message);
		if ($this->isColumnModified(RingtoneDownloadPeer::SOURCE_TYPE)) $criteria->add(RingtoneDownloadPeer::SOURCE_TYPE, $this->source_type);
		if ($this->isColumnModified(RingtoneDownloadPeer::FROM_PHONE)) $criteria->add(RingtoneDownloadPeer::FROM_PHONE, $this->from_phone);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(RingtoneDownloadPeer::DATABASE_NAME);

		$criteria->add(RingtoneDownloadPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setRingtoneId($this->ringtone_id);

		$copyObj->setUserId($this->user_id);

		$copyObj->setToPhone($this->to_phone);

		$copyObj->setPrice($this->price);

		$copyObj->setAmount($this->amount);

		$copyObj->setDownloadDatetime($this->download_datetime);

		$copyObj->setType($this->type);

		$copyObj->setMessage($this->message);

		$copyObj->setSourceType($this->source_type);

		$copyObj->setFromPhone($this->from_phone);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new RingtoneDownloadPeer();
		}
		return self::$peer;
	}

} 